package xyz.xtt.equity.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.asset.client.AssetClient;
import xyz.xtt.asset.client.request.AssetNoInfoRequest;
import xyz.xtt.asset.client.request.DeliverRequest;
import xyz.xtt.asset.client.response.AssetAccountResponse;
import xyz.xtt.asset.client.response.TblAssetNoDto;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.equity.service.IInnerService;
import xyz.xtt.pay.client.PayClient;
import xyz.xtt.pay.client.response.BusinessOrderResponse;
import xyz.xtt.pay.client.response.TblPayOrderDto;
import xyz.xtt.user.client.UserClient;
import xyz.xtt.user.client.response.UserInfoResponse;

@Slf4j
@Service
public class IInnerServiceImpl implements IInnerService {
	@Autowired
	private UserClient userClient;
	@Autowired
	private AssetClient assetClient;
	@Autowired
	private PayClient payClient;

	@Override
	public UserInfoResponse userInfo(Long appUid) {
		ApiResult<UserInfoResponse> response = userClient.info(appUid);
		log.info("userClient userInfo one response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

	@Override
	public AssetAccountResponse accountInfoUnCheckAmount(Long assetId, Long appUid) {
		ApiResult<AssetAccountResponse> response = assetClient.accountInfoUnCheckAmount(assetId, appUid);
		log.info("assetClient accountInfoCheckAmount response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

	@Override
	public Boolean deliver(DeliverRequest request) {
		ApiResult<Boolean> response = assetClient.deliver(request);
		log.info("assetClient deliver response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, Boolean.FALSE);
	}

	@Override
	public TblPayOrderDto fetchPayOrder(Long payOrderId) {
		ApiResult<TblPayOrderDto> response = payClient.fetchPayOrder(payOrderId);
		log.info("assetClient deliver response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

	@Override
	public List<TblAssetNoDto> getNFTNoInfo(AssetNoInfoRequest assetNoInfoRequest) {
		ApiResult<List<TblAssetNoDto>> response = assetClient.getNFTNoInfo(assetNoInfoRequest);
		log.info("assetClient getNFTNoInfo response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, Lists.newArrayList());
	}

	@Override
	public BusinessOrderResponse businessOrderInfoWithId(Long businessOrderId) {
		ApiResult<BusinessOrderResponse> response = payClient.businessOrderInfoWithId(businessOrderId);
		log.info("payClient businessOrderInfoWithId response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

}
